
	$(document).ready(function(){
			
			/******************LOGIN************************/
			
			$('#loginbtn').click(function(){
			$.ajax({
				    type: "POST",
				    url: "user/login",
				    data: $('.loginform').serialize(),
				    success: function(q) {
				    		var result = $.parseJSON(q);
				    		if(result['error']){
								$('#loginBox').addClass('error');
								$('#loginError').html(""+result['error_msg']+"");
								$('.signupCallout').css('display','none');
								$('.loginBoxError').css('display','block');
                                $('#loginbtn').css('color','white');
                                $('#loginbtn').css('border-color',"rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25)");
							}
							else{
								window.location="home";
							}
				    }
				});
				return false;
			});
			
			/*****************REGISTRATION**********************/
			
			$('#registerbtn').click(function(){
			$.ajax({
				    type: "POST",
				    url: "user/signup",
				    data: $('.regform').serialize(),
				    success: function(q) {
				    		var result = $.parseJSON(q);
				    		if(result['error']){
								$('#signupError').html(""+result['error_msg']+"");
								$('.signupCallout').css('display','block');
								$('.loginBoxError').css('display','none');
								$('#loginBox').removeClass('error');
							}
							else{
								alert(result['message']);
								$('.regform #name').val('');
								$('.regform #email').val('');
								$('.regform #password').val('');
								$('.regform #password2').val('');
								//window.location="user/home";
							}
				    }
				});
			return false;
			});	
			
			/******************WALL************************/
			
			$('#postbtn').click(function(){
			$.ajax({
				    type: "POST",
				    url: "home/post",
				    data: $('.postboxform').serialize(),
				    success: function(q) {
				    		var result = $.parseJSON(q);
				    		if(result['success']){
								$('#postbox').val('');
								$('#wall').prepend(result['html']);
								$('#wall').fadeIn();
                             }
					}
				});
				return false;
			});
			
			$('.newpost').mouseover(function(){
				var id = $(this).attr('id');
                $('#removepost_'+id).css('display','block')
			});
			$('.newpost').mouseout(function(){
            	var id = $(this).attr('id');
            	$('#removepost_'+id).css('display','none')
			});
            
			$('.removebtn').click(function(){         
			$.ajax({
				    type: "POST",
				    url: "home/removepost",
				    data: "id="+$(this).attr('id'),
				    success: function(q) {
				    		if(q){
                                $('#'+q+'.newpost').fadeOut('slow');
                                }
                            }
				});
				return false;
			});
	
	});//end document ready
